#!/usr/bin/env python 
# -*- coding:utf-8 -*-
"""
@Time:2022/3/6 下午8:41"
@Author:lydia_liu"
@File:product_comment.py
@function:
"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from litemallPrac.page.base_page import BasePage


class ProductComment(BasePage):

    #回复按钮
    __button_reply = (By.XPATH,'//*[@class="el-table__row"]//td[7]//button[1]')
    #回复内容
    _input_reply = (By.XPATH,'//*[@class="el-textarea__inner"]',"回复内容")
    #确定按钮
    _button_confirm = (By.XPATH,'//span[contains(text(),"确定")]')

    #回复成功提示
    _message_success = (By.XPATH,'//*[contains(text(),"回复成功")]')

    #删除按钮
    _button_delect = (By.XPATH,'//*[@class="el-table__body"]//tr[1]//td[7]//button[2]')
    _massage_delectsuccess = (By.XPATH,'//*[contains(text(),"删除成功")]')
    def comment_product(self):

        #在商品评论页面，点击回复按钮
        self.on_click(*self.__button_reply)
        #输入回复内容
        self.sendkeys(*self._input_reply)
        #点击确定按钮
        self.on_click(*self._button_confirm)

        #显示等待获取回复成功提示
        confirm_message = WebDriverWait(self.driver,10).until(expected_conditions.visibility_of_element_located(self._message_success)).text
        print(confirm_message)
        return confirm_message

    def delect_comment(self):#删除评论
        #在商品评论页面，点击删除按钮
        self.on_click(*self._button_delect)
        #获取删除成功提示
        delect_message = WebDriverWait(self.driver,10).until(expected_conditions.visibility_of_element_located(self._massage_delectsuccess)).text
        return delect_message
